package ui.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.fy.fyzf.R;
import com.fy.fyzf.bean.MessageListBean;
import com.fy.fyzf.weight.DragBubbleView;

import java.util.List;

import ui.activity.MessageActivity;

public class MessageAdapter extends BaseQuickAdapter<MessageListBean.ListBean, BaseViewHolder> {

    private Context mContext;
    public MessageAdapter(Context context) {
        super(R.layout.item_message);
        mContext = context;
    }

    public void removeItem(int i) {
        getData().remove(i);
        notifyItemRemoved(i);
    }
    @Override
    protected void convert(BaseViewHolder helper, MessageListBean.ListBean item) {
        helper.setText(R.id.tv_title, item.getMsgTitle())
                .setText(R.id.tv_content, item.getMsgContent())
                .setText(R.id.tv_time, item.getCreateTime());

        helper.addOnClickListener(R.id.tv_delete);
        DragBubbleView dragBubbleView = helper.getView(R.id.tv_read);
        dragBubbleView.setText("1");
        if (item.getMsgStart() == 0) {  //1已读
            dragBubbleView.setVisibility(View.VISIBLE);
        } else {
            dragBubbleView.setVisibility(View.GONE);
        }

        dragBubbleView.setOnBubbleStateListener(new DragBubbleView.OnBubbleStateListener() {
            @Override
            public void onDrag() {

            }

            @Override
            public void onMove() {

            }

            @Override
            public void onRestore() {

            }

            @Override
            public void onDismiss() {
                MessageActivity messageActivity = (MessageActivity) mContext;
                messageActivity.setReady(item.getMsgId());

            }
        });

    }
}
